<template>
  <div class="goods-hot">
    <h3>{{ listName }}</h3>
    <GoodsItem
      v-for="item in hotData"
      :key="item"
      :valueItem="item"
    ></GoodsItem>
  </div>
</template>

<script>
import GoodsItem from "../category/GoodsItem";
import { getHotData } from "../../api/goods";
import { ref } from "vue";
import { useRoute } from "vue-router";

export default {
  name: "GoodsHot",
  components: { GoodsItem },
  props: ["type"],
  setup(props) {
    let { hotData, listName } = fnGetHotGoodData(props.type);

    return {
      hotData,
      listName,
    };
  },
};

// 获取热销商品数据
function fnGetHotGoodData(type) {
  const route = useRoute();
  const allname = {
    1: "24小时热销榜",
    2: "周热销榜",
    3: "总热销榜",
  };
  // 存放热销商品
  let hotData = ref([]);

  getHotData(route.params.id, type).then((res) => {
    hotData.value = res.result;
  });

  return {
    hotData,
    listName: allname[type],
  };
}
</script>

<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  :deep(.goods-item) {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;

    img {
      width: 200px;
      height: 200px;
    }

    p {
      margin: 0 10px;
    }

    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>
